package com.pearl.utils;

import com.alibaba.fastjson.JSONObject;
import com.pearl.entitys.beans.UserToken;

public class WebContextUtil {


  //本地线程缓存token
  private static ThreadLocal<String> local = new ThreadLocal<>();

  /**
   * 获取token信息
   */
  public static UserToken getUserToken() {
    if (local.get() != null) {
      UserToken userToken = JSONObject.parseObject(local.get(), UserToken.class);
      return userToken;
    }
    return null;
  }

  /**
   * 设置token信息
   */
  public static void setUserToken(String content) {
    removeUserToken();
    local.set(content);
  }

  /**
   * 移除token信息
   */
  public static void removeUserToken() {
    if (local.get() != null) {
      local.remove();
    }
  }


}
